<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>行政区管理</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../../plugins/element-ui/index.css"/>
    <link rel="stylesheet" href="../../styles/common.css"/>
    <link rel="stylesheet" href="../../styles/page.css"/>
</head>
<body>
<div class="dashboard-container" id="driver-app">
    <div class="container">
        <div class="tableBar">
            <div class="tableLab">
                行政区编码：<el-input v-model="conditions.code" placeholder="请输入行政区编码" style="width: 250px" clearable></el-input>
                行政区名称：<el-input v-model="conditions.name" placeholder="请输入行政区名称" style="width: 250px" clearable ></el-input>
                <el-button  type="primary" @click="init()" icon="el-icon-search"> 搜索 </el-button>
            </div>
        </div>
        <el-table  :data="pagination.tableData"  stripe  class="tableBox">
            <el-table-column type="index" width="50" label="序号"></el-table-column>
            <el-table-column prop="code" label="行政区编码"></el-table-column>
            <el-table-column  prop="name" label="名称"  /></el-table-column>
            <el-table-column  prop="level" label="等级"  />
                <template slot-scope="scope">
                    <span v-if="scope.row.level==1">省</span>
                    <span v-if="scope.row.level==2">地级市</span>
                    <span v-if="scope.row.level==3">区/县</span>
                    <span v-if="scope.row.level==4">乡/镇</span>
                </template>
            </el-table-column>
            <el-table-column prop="type" label="类型" >
                <template slot-scope="scope">
                    <span v-if="scope.row.type==1">省</span>
                    <span v-if="scope.row.type==2">自治区</span>
                    <span v-if="scope.row.type==3">直辖市</span>
                    <span v-if="scope.row.type==4">特别行政区</span>
                    <span v-if="scope.row.type==5">地级市</span>
                    <span v-if="scope.row.type==6">地区</span>
                    <span v-if="scope.row.type==7">自治州</span>
                    <span v-if="scope.row.type==8">盟</span>
                    <span v-if="scope.row.type==9">市辖区</span>
                    <span v-if="scope.row.type==10">县</span>
                    <span v-if="scope.row.type==11">县级市</span>
                    <span v-if="scope.row.type==12">自治县</span>
                    <span v-if="scope.row.type==13">旗</span>
                    <span v-if="scope.row.type==14">自治旗</span>
                    <span v-if="scope.row.type==15">特区</span>
                    <span v-if="scope.row.type==16">林区</span>
                </template>
            </el-table-column>
            <el-table-column  prop="abname" label="简称"  /></el-table-column>
            <el-table-column  prop="pid" label="父编码"></el-table-column>
            <el-table-column  prop="pname" label="父名称"  /></el-table-column>
            <el-table-column prop="note"  label="备注" ></el-table-column>
        </el-table>
        <el-pagination
                class="pageList"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pagination.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pagination.counts"
                @size-change="handleSizeChange"
                :current-page.sync="pagination.page"
                @current-change="handleCurrentChange"
        ></el-pagination>
    </div>
    <el-dialog :title="classData.title" :visible.sync="classData.dialogVisible" width="60%" :before-close="handleClose">
        <el-table  :data="classData.list"  stripe  class="tableBox">
            <el-table-column  type="index" width="50" label="序号"></el-table-column>
            <el-table-column prop="code" label="行政区编码"></el-table-column>
            <el-table-column  prop="name" label="名称"  /></el-table-column>
            <el-table-column  prop="level" label="等级"  />
                <template slot-scope="scope">
                    <span v-if="scope.row.level==1">省</span>
                    <span v-if="scope.row.level==2">地级市</span>
                    <span v-if="scope.row.level==3">区/县</span>
                    <span v-if="scope.row.level==4">乡/镇</span>
                </template>
            </el-table-column>
            <el-table-column prop="type" label="类型" >
                <template slot-scope="scope">
                    <span v-if="scope.row.type==1">省</span>
                    <span v-if="scope.row.type==2">自治区</span>
                    <span v-if="scope.row.type==3">直辖市</span>
                    <span v-if="scope.row.type==4">特别行政区</span>
                    <span v-if="scope.row.type==5">地级市</span>
                    <span v-if="scope.row.type==6">地区</span>
                    <span v-if="scope.row.type==7">自治州</span>
                    <span v-if="scope.row.type==8">盟</span>
                    <span v-if="scope.row.type==9">市辖区</span>
                    <span v-if="scope.row.type==10">县</span>
                    <span v-if="scope.row.type==11">县级市</span>
                    <span v-if="scope.row.type==12">自治县</span>
                    <span v-if="scope.row.type==13">旗</span>
                    <span v-if="scope.row.type==14">自治旗</span>
                    <span v-if="scope.row.type==15">特区</span>
                    <span v-if="scope.row.type==16">林区</span>
                </template>
            </el-table-column>
            <el-table-column  prop="abname" label="简称"  /></el-table-column>
            <el-table-column  prop="pid" label="父编码"></el-table-column>
            <el-table-column  prop="pname" label="父名称"  /></el-table-column>
            <el-table-column prop="note"  label="备注" ></el-table-column>
        </el-table>
    </el-dialog>
</div>
<script src="../../plugins/vue/vue.js"></script>
<script src="../../plugins/element-ui/index.js"></script>
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/area.js"></script>
<script type="text/javascript">
    new Vue({
        el: '#driver-app',
        data() {
            return {
                action: '',
                pagination: {
                    tableData: [],
                    page: 1,
                    pageSize: 10,
                    counts:0,
                },
                conditions:{
                    code:'',
                    name:'',
                },
                classData:{
                    title:'',
                    dialogVisible:false,
                    list:[],
                    driverName:''
                }
            }
        },
        methods: {
            async init() {
                const params = {
                    page: {
                        current: this.pagination.page,//当前页码
                        size: this.pagination.pageSize,//每页大小
                    },
                    name: this.conditions.name ? this.conditions.name : undefined,//名称
                    code: this.conditions.code ? this.conditions.code : undefined//编码
                };
                await findAreaPage(params).then(res => {
                    if (String(res.code) === '200') {
                        this.pagination.tableData = res.data.records;
                        this.pagination.counts = res.data.total;
                    } else {
                        this.$message.error(res.msg || '操作失败')
                    }
                }).catch(err => {
                    this.$message.error('请求出错了：' + err)
                })
            },
            handleQuery() {
                this.page = 1;
                this.init();
            },
            // 关闭弹窗
            handleClose(st) {
                this.classData.dialogVisible = false
            },
            // 全部操作
            handleSelectionChange(val) {
                let checkArr = [];
                val.forEach((n) => {
                    checkArr.push(n.id)
                })
                this.checkList = checkArr
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.init()
            },
            handleCurrentChange(val) {
                this.page = val;
                this.init()
            }
        },
        created() {
            this.init()
        }
    })
</script>
</body>
</html>